package com.yien.springstudy.service.impl;

import com.yien.springstudy.service.StringService;
import org.springframework.stereotype.Service;

/**
 * @author Miaoxiong Fan
 * @since version
 */
@Service
public class StringServiceImpl implements StringService {

    @Override
    public void testParseToString() {
        Integer num  = 0;
        int loop = 100000;  // 将结果放大100000倍，以便于观察结果
        long beginTime = System.currentTimeMillis();
        for (int i = 0; i < loop; i++) {
            String s = num+"";
        }
        long endTime = System.currentTimeMillis();
        System.out.println("+\"\"的方式耗时: " + (endTime - beginTime) + "ms");


        beginTime = System.currentTimeMillis();
        for (int i = 0; i < loop; i++) {
            String s = String.valueOf(num);
        }
        endTime = System.currentTimeMillis();
        System.out.println("String.valueOf()的方式耗时: " + (endTime - beginTime) + "ms");

        beginTime = System.currentTimeMillis();
        for (int i = 0; i < loop; i++) {
            String s = num.toString();
        }
        endTime = System.currentTimeMillis();
        System.out.println("toString()的方式耗时: " + (endTime - beginTime) + "ms");
    }
}
